import { listConsumableCategoryTree } from '@/apis/asset/common';
import type { TreeNodeData } from '@arco-design/web-vue';
import { ref } from 'vue';

/** 耗材类型模块 */
export function consumableCategory(options?: { onSuccess?: () => void }) {
  const loading = ref(false)
  const consumableCategoryList = ref<TreeNodeData[]>([])

  const getConsumableCategoryList = async (name?: string) => {
    try {
      loading.value = true
      const res = await listConsumableCategoryTree({ description: name })
      consumableCategoryList.value = res.data
      options?.onSuccess && options.onSuccess()
    } finally {
      loading.value = false
    }
  }
  return { consumableCategoryList, getConsumableCategoryList, loading }
}
